﻿<?php

require_once '../actions/handler/renren/RenrenRestApiService.class.php';
require_once "../actions/db.class.php";
require_once "../actions/config.php";

$sessionKey = $_GET['xn_sig_session_key'];
$uid = $_GET['uid'];
$choice = $_GET['choice'];

$amounts = array('0'=>'10','1'=>'50','2'=>'100','3'=>'200','4'=>'500');
$amount= $amounts[$choice];

$rrObj = new RenrenRestApiService;
list($usec, $sec) = explode(" ", microtime()); 
$order_id = $sec.($usec * 1000000);
$desc = '元宝';

//记录订单信息
$dbParams = array("host"=>"$host", "user"=>"$user", "pass"=>"$pass", "db"=>"$db");
$db = new Dbclass($dbParams, false);


$sql = "insert into ".$tb_order_profile." (orderId, amount, renrenId) values (".$order_id.",".$amount.",".$uid.")";
$db->query($sql);
if ($db->affectedRows() > 0)
{
	$params = array('order_id'=>$order_id,'amount'=>$amount,'desc'=>$desc,'session_key'=>$sessionKey);
	$token = $rrObj->rr_post_curl('pay.regOrder', $params);
	$res = array('order_id'=>$order_id,'amount'=>$amount,'token'=>$token['token'],'order_uid'=>$uid);
	echo json_encode($res);
}

?>
